var sendMessageToContentScript = function(message, callback)
{
    chrome.tabs.query({active: true, currentWindow: true}, function(tabs)
    {
        chrome.tabs.sendMessage(tabs[0].id, message, function(response)
        {
            if(callback) callback(response);
        });
    });
}

chrome.contextMenus.create({
    title: "测试右键菜单",
    onclick: function(){
    	// alert('您点击了右键菜单！');
    	//console.log('您点击了右键菜单！');

    	/*发送消息的*/
		sendMessageToContentScript({cmd:'test', value:'你好，我是popup！'}, function(response)
		{
			//alert('来自content的回复：'+response);
		    //console.log('来自content的回复：'+response);
		});
    }
});


chrome.browserAction.onClicked.addListener(function(){
    chrome.browserAction.setTitle({
        title:"newTitle"
    });

    chrome.browserAction.setPopup({
        popup:"http://127.0.0.1/pop.php"
    });
});
